package com.lecampus.businessCampus_moments.controller;


import com.lecampus.businessCampus_moments.entity.ArticleComment;
import com.lecampus.businessCampus_moments.service.ArticleCommentService;
import com.lecampus.businessCampus_moments.vo.ArticleCommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/lecampus/article")
public class ArticleCommentController {

    @Autowired
    private ArticleCommentService articleCommentService;

    @GetMapping("/{articleId}/comments/currentPage={currentPage}&size={size}")
    public List<ArticleCommentVO> findAllComments(@PathVariable("articleId") String articleId,
                                                  @PathVariable("currentPage") long currentPage,
                                                  @PathVariable("size") long size) {
        return articleCommentService.findCommentsByArticleId(articleId,currentPage,size);
    }

    @PostMapping("/{articleId}/comment/input")
    public void inputComment(@PathVariable("articleId") String articleId,
                             ArticleComment comment) {
        articleCommentService.inputComment(articleId,comment);
    }

    @GetMapping("/{articleId}/comment/{commentId}/delete")
    public void deleteComment(@PathVariable("articleId") String articleId,
                              @PathVariable("commentId") String commentId) {
        articleCommentService.deleteByCommentId(articleId,commentId);
    }

    @GetMapping("/comment/{articleCommentId}/like/flag={flag}")
    public void likes(@PathVariable("articleCommentId") String articleCommentId,
                      @PathVariable("flag") int flag) {
        articleCommentService.likes(articleCommentId,flag);
    }
}

